<template>
    <div style="margin-top: 20px">

        <el-dialog title="添加或修改服务信息" :visible.sync="dialogFormVisible">
            <el-form :model="form" label-width="100px">
                <el-form-item label="名字">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="售价">
                    <el-input v-model="form.saleprice" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select  label-width="300px" v-model="form.state" placeholder="服务状态">
                        <el-option label="下架" value="0"></el-option>
                        <el-option label="上架" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="成本价">
                    <el-input v-model="form.costprice" autocomplete="off"></el-input>
                </el-form-item>


            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveOrUpdateDept">确 定</el-button>
            </div>
        </el-dialog>

        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline">
            <el-form-item label="服务名称">
                <el-input v-model="searchForm.name" placeholder="服务名称"></el-input>
            </el-form-item>
            <el-form-item label="服务状态">
                <el-select v-model="searchForm.state" placeholder="服务状态">
                    <el-option label="下架" value="0"></el-option>
                    <el-option label="上架" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="toQuery">查询</el-button>
                <el-button type="success" @click="dialogFormVisible = true">新增</el-button>
                <!--<el-button type="success" @click="onSubmit">宠物上架</el-button>-->
                <!--<el-button type="warning" @click="onSubmit">宠物下架</el-button>-->
                <el-button type="danger" @click="onSubmit">批量删除</el-button>
            </el-form-item>
        </el-form>

        <el-table
                :data="tableData"
                style="width: 100%"
                @selection-change="handleSelectionChange">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="名字">
            </el-table-column>
            <el-table-column
                    prop="resources"
                    label="图片"
                    width="120">
                <template slot-scope="scope">
                    <el-image :src="scope.row.resourcesUrl?scope.row.resourcesUrl.split(',')[0]:''"></el-image>
                    <!--item.resourcesUrl?item.resourcesUrl.split(',')[0]:''-->
                </template>
            </el-table-column>


            <el-table-column
                    prop="saleprice"
                    label="售价">
            </el-table-column>

            <el-table-column
                    prop="state"
                    label="状态">
                <template slot-scope="scope">-->
                    <el-tag type="danger" v-if="scope.row.state == 0">下架</el-tag>
                    <el-tag type="success" v-if="scope.row.state == 1">上架</el-tag>
                </template>
            </el-table-column>

            <el-table-column
                    prop="costprice"
                    label="成本价">
            </el-table-column>


            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.row)">编辑
                    </el-button>
                    <el-popover
                            placement="top"
                            width="160"
                            v-model="visible">
                        <p>这是一段内容这是一段内容确定删除吗？</p>
                        <div style="text-align: right; margin: 0">
                            <el-button size="mini" type="text" @click="visible = false">取消</el-button>
                            <el-button type="primary" size="mini" @click="handleDelete(scope.row)">确定</el-button>
                        </div>
                        <el-button slot="reference">删除</el-button>
                    </el-popover>

                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="searchForm.currPage"
                :page-sizes="[1, 2, 3, 4]"
                :page-size="searchForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
</template>
<script>
    export default {
        data() {
            return {

                query: {
                    typesId: 0,
                    currPage: 1,
                    pageSize: 10
                },
                options: [],
                form: {},//这个对象用于保存表单提交时的数据
                dialogFormVisible: false,
                tableData: [],
                parentDepts: [],
                multiIdSelcts: [], // 用于保存复选框选中的值
                multipleSelection: [],
                searchForm: {//查询条件
                    currPage: 1,
                    pageSize: 4
                },
                total: 0, //分页的总记录条数
                tableData: [],
                petTypeList: []
            }
        },
        methods: {
            handleDelete(row) {

                this.$http.get('/fuwu/del?id=' + row.id).then(res => {

                    this.toQuery();
                })
                visible = false;
            },
            onSubmit(){

            },
            handleEdit(row) {
                this.dialogFormVisible = true;
                this.form = row;

            },
            saveOrUpdateDept() {
                this.$http.post('/fuwu/saveorupdate', this.form).then(res => {
                    this.dialogFormVisible = false;
                    this.toQuery();
                })
            },
            toQuery() {
                console.log(">>>>>>>>>>" + JSON.stringify(this.searchForm))
                this.$http.post("/fuwu/findpage", this.searchForm).then(res => {
                    this.total = res.data.total;
                    this.tableData = res.data.rows;
                })
            },

            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                this.searchForm.pageSize = val;
                this.toQuery();
            },
            handleCurrentChange(val) {
                this.searchForm.currPage = val;
                this.toQuery();
            }

        },
        mounted() {
            this.toQuery();
            this.findAllType();
        }


    }
</script>